<%
   plans_select_box_id = "plans-#{params[:issue]}"
   plans = Internal.issues.findOpenActionPlans(@issue_result.project(@issue).key())
   if plans.empty?
%>
  <% if is_admin? %>
    <span class="error"><%= message('issue.plan.error.plan_must_be_created_first_for_admin',
                                    :params => ApplicationController.root_context + '/action_plans/index/' + @issue_result.project(@issue).key()) -%></span>
  <% else %>
    <span class="error"><%= message('issue.plan.error.plan_must_be_created_first_for_other') -%></span>
  <% end %>
  &nbsp;<%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>
<%
   else
     first_plan = plans[0]
     options = plans.map { |plan|
       label = plan.deadLine ? "#{h plan.name} (#{format_date(plan.deadLine)})" : h(plan.name)
       [label, plan.key]
     }
     if @issue.actionPlanKey
      options.unshift([escape_javascript(message('issue.unplan.submit')), ''])
     end
     plan_options = options_for_select(options, first_plan.key)
%>
  <form method="POST">
    <input type="hidden" name="issue" value="<%= params[:issue] -%>"/>
    <input type="hidden" id="action-<%= plans_select_box_id %>" name="id" value="plan"/>

    <%= dropdown_tag('plan', plan_options, {:show_search_box => false}, {:id => plans_select_box_id}) -%>

    <input type="button" value="<%= message('issue.plan.submit') -%>" onclick="submitIssueForm(this)">&nbsp;
    <%= link_to_function message('cancel'), 'closeIssueForm(this)', :class => 'action' -%>
    <span class="loading hidden"></span>

  </form>

<% end %>
